﻿using Inovout.Organizations.Models;
using Inovout.Security;
using System;
using System.ComponentModel.DataAnnotations;

namespace Inovout.Account.Web.Models
{
    public class OrganizationSignUpInfo : SignUpInfo
    {
        [Required(ErrorMessage = "机构名称不可为空")]
        [Alias("机构名称")]
        public string OrganizationName { get; set; }

        [Required(ErrorMessage = "邮箱地址不可为空")]
        [EmailAddress(ErrorMessage = "请输入正确的邮箱格式")]
        [RegularExpression("^((?!@samples.cn).)*$", ErrorMessage = "该邮箱已存在")]
        [Alias("机构邮箱地址")]
        public string OrganizationEmail { get; set; }


        public OrganizationUnit Organization
        {
            get
            {
                return new OrganizationUnit { Name = OrganizationName, Email = OrganizationEmail };
            }
        }
          public FormsUserCredential FormsUserCredential
        {
            get
            {
                SystemUser systemUser = new SystemUser();
                systemUser.Name = Guid.NewGuid().ToString();
                return new FormsUserCredential
                {
                    Email = OrganizationEmail,
                    AccountName = OrganizationName,
                    Provider = "Inovout",
                    Identifier = Guid.NewGuid().ToString(),
                    UserName = UserName,
                    Password = Password,
                    SystemUser = systemUser
                };
            }
        }

        public OpenIdUserCredential OpenIdUserCredential
        {
            get
            {
                SystemUser systemUser = new SystemUser();
                systemUser.Name = OpenIdUserName;
                return new OpenIdUserCredential
                {
                    Email = OrganizationEmail,
                    AccountName = OrganizationName,
                    Provider = OpenIdProvider,
                    Identifier = OpenIdClaimedIdentifier,
                    SystemUser = systemUser
                };
            }
        }

        public OAuthUserCredential OAuthUserCredential
        {
            get
            {
                SystemUser systemUser = new SystemUser();
                systemUser.Name = OpenIdUserName;
                return new OAuthUserCredential
                {
                    Email = OrganizationEmail,
                    AccountName = OrganizationName,
                    Provider = OpenIdProvider,
                    Identifier = OpenIdClaimedIdentifier,
                    Code = Code,
                    AccessToken = AccessToken,
                    AccessTokenExpiredTime = AccessTokenExpiredTime,
                    RefreshToken = RefreshToken,
                    RefreshTokenExpiredTime = RefreshTokenExpiredTime,
                    SystemUser = systemUser
                };
            }
        }
    }
}